<template>
  <div class="menu-wrapper">
    <div class="menu-card">
      <!-- 背景图层 -->
      <div class="background-image"></div>

      <header class="menu-header">
        <h1 class="welcome">欢迎，{{ userStore.username }}</h1>
        <button class="logout-btn" @click="logout">退出</button>
      </header>

      <nav class="menu-nav">
        <router-link class="nav-link" to="/">首页</router-link>
        <router-link class="nav-link" to="/menu">菜单</router-link>
        <router-link class="nav-link" to="/cart">购物车</router-link>
        <router-link class="nav-link" to="/checkout">结算</router-link>
        <router-link
          v-if="userStore.permissions.includes('ADMIN')"
          class="nav-link"
          to="/admin/users"
        >用户管理</router-link>
        <router-link
          v-if="userStore.permissions.includes('MERCHANT')"
          class="nav-link"
          to="/admin/dishes"
        >菜品管理</router-link>
        <router-link
          v-if="userStore.permissions.includes('ADMIN')"
          class="nav-link"
          to="/admin/orders"
        >订单管理</router-link>
        <router-link
          v-if="userStore.permissions.includes('ADMIN')"
          class="nav-link"
          to="/admin/reviews"
        >评价管理</router-link>
      </nav>

      <main class="menu-main">
        <router-view />
      </main>
    </div>
  </div>
</template>

<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/user'

const router = useRouter()
const userStore = useUserStore()

function logout() {
  userStore.logout()
  router.push('/login')
}
</script>

<style scoped>
/* 背景与居中 */
.menu-wrapper {
  min-height: 100vh;
  background: linear-gradient(to bottom, #f8fafc, #e2e8f0);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 3rem 1rem;
  box-sizing: border-box;
}

/* 卡片容器 */
.menu-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 850px;
  background-color: #ffffff;
  border-radius: 24px;
  padding: 2.5rem 2rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  text-align: center;
}

/* 背景图层样式 */
.background-image {
  position: absolute;
  inset: 0;
  background-image: url('@/assets/images/background.png'); /* 修改为你的图片路径 */
  background-size: cover;
  background-position: center;
  opacity: 0.35; /* 控制透明度，建议 0.1 ~ 0.25 */
  z-index: 0;
}

/* 保证前景内容在上面 */
.menu-card > *:not(.background-image) {
  position: relative;
  z-index: 1;
}

/* 顶部区域 */
.menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.welcome {
  font-size: 2rem;
  font-weight: 700;
  color: #0f172a;
}

.logout-btn {
  background-color: #0f172a;
  color: white;
  border: none;
  padding: 0.6rem 1.2rem;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background-color 0.3s;
}

.logout-btn:hover {
  background-color: #1e293b;
}

/* 导航栏 */
.menu-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.nav-link {
  padding: 0.75rem 1.4rem;
  background-color: #f1f5f9;
  border-radius: 12px;
  text-decoration: none;
  color: #0f172a;
  font-weight: 500;
  font-size: 0.95rem;
  transition: background-color 0.25s;
}

.nav-link:hover {
  background-color: #e2e8f0;
}

/* 主视图区域 */
.menu-main {
  background-color: #f9fafb;
  padding: 1.5rem;
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  min-height: 300px;
  text-align: left;
}
</style>
